/**
 * Created by sxx on 2017/5/6.
 */
import "./index.less";
import "../../../unit/common/js/bootstrap_js/select2.min.js";
import "../../../unit/common/js/bootstrap_js/jquery.dataTables.js";
import "../../../unit/common/js/bootstrap_js/form-samples.js";
import httpurl from "../../../unit/common/js/httpurl";
import {qotCntTyp, matUnt} from "../config";
import bidInfoTpl from "./bid_info.handlebars";
import bidProdTpl from "./bid_prod.handlebars";


jQuery(function () {
    App.init();

    Date.prototype.Format = function (fmt) { //author: meizz
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    };

    var id = httpurl.uri.params.id;
    var bidId = httpurl.uri.params.bidId;
    let token = sessionStorage.getItem('supplier_token');

    // 查看排名
    $('.J_check').click(function(item){
        let qotId = item.data('id');
        console.log('qotId:'+qotId);

        // $.ajax({
        //     url: HOST_ADDR + '/cpmp/bidProjOnMngForSplr/getQotOrder/' + qotId,
        //     type: 'post',
        //     data: JSON.stringify(data),
        //     dataType: 'json',
        //     contentType:"application/json",
        //     access_token: token,
        //     headers: {
        //         'access_token': token
        //     },
        //     success: function(resp){
        //         if(resp.success){
        //             console.log(resp);
        //             alert('报价成功');
        //             location.href = '/my_bidding_list.html';
        //         }
        //     },
        //     error:function(err){
        //         console.log(err);
        //     }
        // });

    });

    jQuery.ajax({
//        url: 'http://47.92.5.0:8080/cpmp/bidProjOn/queryByConds/1/20',cpmp/bidProjOnMngForSplr/viewProjDtl/1
        url: HOST_ADDR + '/cpmp/bidProjOnMngForSplr/getQotInf/' + id,
        type: 'get',
        // data: JSON.stringify(data),
        dataType: 'json',
        contentType:"application/json",
        access_token: token,
        headers: {
            'access_token': token,
            'login_type': 'splr'
        },
        success: function(resp){
            // console.log(resp);
            if (!resp.success) {
                console.log(resp.msgCod+' '+resp.msgInf);
                return;
            }
            resp.data.qotCntTyp = qotCntTyp[resp.data.qotCntTyp] || '';
            resp.data.bidRngTyp=resp.data.bidRngTyp == 1?'定向招标':'非定向招标';

            if (resp.data.bidOpenTim != null&&resp.data.bidOpenTim !='') {
                resp.data.bidOpenTim = (new Date(resp.data.bidOpenTim)).Format("yyyy-MM-dd hh:mm:ss");
            } else {
                resp.data.bidOpenTim = '';
            }
            if (resp.data.bidEndTim != 'null'&&resp.data.bidEndTim !='') {
                resp.data.bidEndTim = (new Date(resp.data.bidEndTim)).Format("yyyy-MM-dd hh:mm:ss");
            } else {
                resp.data.bidEndTim= '';
            }
            $.each(resp.data.qotDtls,function(index,item){
                item.matUntFmt = matUnt[item.matUnt] || "个";
                console.log(item.matUnt);
            });

            let infoHtml = bidInfoTpl(resp.data);
            let prodHtml = bidProdTpl({matDtls: resp.data.qotDtls});

            jQuery('.basicInfo').html(infoHtml);
            jQuery('.basicInfo').after(prodHtml);
            console.log(resp)


        },
        error:function(err){
            console.log(err);
        }
    });
});